#include <algorithm>
#include <cstdint>
#include <functional>
#include <iostream>
#include <map>
#include <set>
#include <tuple>
#include <unordered_set>
#include <vector>
using namespace std;

class Solution {
public:
    vector<vector<int>> threeSum(vector<int>& nums) {
        vector<vector<int>> res;
        set<vector<int>> s;
        map<int,int> m;
        for(int i=0;i<nums.size();i++){
            m[nums[i]]++;
        }
        for(int i=0;i<nums.size();i++){
            for(int j=i+1;j<nums.size();j++){
                if(auto p =m.find(-(nums[i]+nums[j]));p!=m.end()){
                    if(nums[i]==nums[j]){
                        auto p = m.find(nums[i]);
                        if(p->second>2)goto ok;
                    }else{
                        
                    }
                    continue;
                    ok:;
                    vector<int> nn={nums[i],nums[j],-(nums[i]+nums[j])};
                    sort(nn.begin(),nn.end());
                    if(s.find(nn)==s.end()){
                        res.push_back(nn);
                        s.insert(nn);
                    }
                }
            }
        }
        return res;
    }
};

int main(){

}